home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / GIMP 2.6.8 / gimp-2.6.8-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / fuzzyborder.scm < prev    next >
Text File  |  2009-12-15  |  6KB  |  167 lines

  1. ;
  2. ; fuzzy-border
  3. ;
  4. ; Do a cool fade to a given colour at the border of an image (optional shadow)
  5. ; Will make image RGB if it isn't already.
  6. ;
  7. ; Chris Gutteridge (cjg@ecs.soton.ac.uk)
  8. ; At ECS Dept, University of Southampton, England.
  9.  
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; This program is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program; if not, write to the Free Software
  22. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ; Define the function:
  25.  
  26. (define (script-fu-fuzzy-border inImage
  27.                                 inLayer
  28.                                 inColor
  29.                                 inSize
  30.                                 inBlur
  31.                                 inGranu
  32.                                 inShadow
  33.                                 inShadWeight
  34.                                 inCopy
  35.                                 inFlatten
  36.         )
  37.  
  38.   (let (
  39.        (theWidth (car (gimp-image-width inImage)))
  40.        (theHeight (car (gimp-image-height inImage)))
  41.        (theImage 0)
  42.        (theLayer 0)
  43.        )
  44.  
  45.     (gimp-context-push)
  46.  
  47.     (gimp-selection-all inImage)
  48.     (set! theImage (if (= inCopy TRUE)
  49.                      (car (gimp-image-duplicate inImage))
  50.                      inImage
  51.                    )
  52.     )
  53.     (if (> (car (gimp-drawable-type inLayer)) 1)
  54.         (gimp-image-convert-rgb theImage)
  55.     )
  56.  
  57.     (set! theLayer (car (gimp-layer-new theImage
  58.                                         theWidth
  59.                                         theHeight
  60.                                         RGBA-IMAGE
  61.                                         "layer 1"
  62.                                         100
  63.                                         NORMAL-MODE)))
  64.  
  65.     (gimp-image-add-layer theImage theLayer 0)
  66.  
  67.  
  68.     (gimp-edit-clear theLayer)
  69.     (chris-color-edge theImage theLayer inColor inSize)
  70.  
  71.     (gimp-layer-scale theLayer
  72.                       (/ theWidth inGranu)
  73.                       (/ theHeight inGranu)
  74.                       TRUE)
  75.  
  76.     (plug-in-spread RUN-NONINTERACTIVE
  77.                     theImage
  78.                     theLayer
  79.                     (/ inSize inGranu)
  80.                     (/ inSize inGranu))
  81.     (chris-color-edge theImage theLayer inColor 1)
  82.     (gimp-layer-scale theLayer theWidth theHeight TRUE)
  83.  
  84.     (gimp-selection-layer-alpha theLayer)
  85.     (gimp-selection-invert theImage)
  86.     (gimp-edit-clear theLayer)
  87.     (gimp-selection-invert theImage)
  88.     (gimp-edit-clear theLayer)
  89.     (gimp-context-set-background inColor)
  90.     (gimp-edit-fill theLayer BACKGROUND-FILL)
  91.     (gimp-selection-none inImage)
  92.     (chris-color-edge theImage theLayer inColor 1)
  93.  
  94.     (if (= inBlur TRUE)
  95.         (plug-in-gauss-rle RUN-NONINTERACTIVE
  96.                theImage theLayer inSize TRUE TRUE)
  97.     )
  98.     (if (= inShadow TRUE)
  99.         (begin
  100.           (gimp-selection-none inImage)
  101.           (gimp-image-add-layer theImage
  102.                                 (car (gimp-layer-copy theLayer FALSE)) 0)
  103.           (gimp-layer-scale theLayer
  104.                             (- theWidth inSize) (- theHeight inSize) TRUE)
  105.           (gimp-desaturate theLayer)
  106.           (gimp-brightness-contrast theLayer 127 127)
  107.           (gimp-invert theLayer)
  108.           (gimp-layer-resize theLayer
  109.                              theWidth
  110.                              theHeight
  111.                              (/ inSize 2)
  112.                              (/ inSize 2))
  113.           (plug-in-gauss-rle RUN-NONINTERACTIVE
  114.                              theImage
  115.                              theLayer
  116.                              (/ inSize 2)
  117.                              TRUE
  118.                              TRUE)
  119.           (gimp-layer-set-opacity theLayer inShadWeight)
  120.         )
  121.     )
  122.     (if (= inFlatten TRUE)
  123.         (gimp-image-flatten theImage)
  124.     )
  125.     (if (= inCopy TRUE)
  126.       (begin
  127.         (gimp-image-clean-all theImage)
  128.         (gimp-display-new theImage)
  129.       )
  130.     )
  131.     (gimp-displays-flush)
  132.  
  133.     (gimp-context-pop)
  134.   )
  135. )
  136.  
  137. (define (chris-color-edge inImage inLayer inColor inSize)
  138.   (gimp-selection-all inImage)
  139.   (gimp-selection-shrink inImage inSize)
  140.   (gimp-selection-invert inImage)
  141.   (gimp-context-set-background inColor)
  142.   (gimp-edit-fill inLayer BACKGROUND-FILL)
  143.   (gimp-selection-none inImage)
  144. )
  145.  
  146. (script-fu-register "script-fu-fuzzy-border"
  147.   _"_Fuzzy Border..."
  148.   _"Add a jagged, fuzzy border to an image"
  149.   "Chris Gutteridge"
  150.   "1998, Chris Gutteridge / ECS dept, University of Southampton, England."
  151.   "3rd April 1998"
  152.   "RGB* GRAY*"
  153.   SF-IMAGE      "The image"               0
  154.   SF-DRAWABLE   "The layer"               0
  155.   SF-COLOR      _"Color"                  "white"
  156.   SF-ADJUSTMENT _"Border size"            '(16 1 300 1 10 0 1)
  157.   SF-TOGGLE     _"Blur border"            TRUE
  158.   SF-ADJUSTMENT _"Granularity (1 is Low)" '(4 1 16 0.25 5 2 0)
  159.   SF-TOGGLE     _"Add shadow"             FALSE
  160.   SF-ADJUSTMENT _"Shadow weight (%)"      '(100 0 100 1 10 0 0)
  161.   SF-TOGGLE     _"Work on copy"           TRUE
  162.   SF-TOGGLE     _"Flatten image"          TRUE
  163. )
  164.  
  165. (script-fu-menu-register "script-fu-fuzzy-border"
  166.                          "<Image>/Filters/Decor")
  167.